package com.cn.kabalifemerchants.ui.user;

import com.cn.kabalifemerchants.api.Api;
import com.cn.kabalifemerchants.base.BasePresenter;
import com.cn.kabalifemerchants.callback.CacheCallBack;
import com.cn.kabalifemerchants.config.Constants;
import com.cn.kabalifemerchants.ui.user.bean.MyUserInfoBean;
import com.cn.kabalifemerchants.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * Created by 晓林 on 2020/10/20.
 * function:
 */
public class FragmentUserPresenter extends BasePresenter<FragmentUserView> {

    public void onUserInfoData(String token) {
        OkGo.<MyUserInfoBean>get(Api.API_USER_INFO)
                .headers("token", token)
                .execute(new CacheCallBack<MyUserInfoBean>() {
                    @Override
                    public void onSuccess(Response<MyUserInfoBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("我的" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onUserInfoSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }
}
